$(function() {
	showCondition(true, 0, 0, 1, []);
	var drg = $("#tabContent > .tab-pane.active").data();
    var monitorType = 'ward';
	paramTabPage[tabId] = drg;
	if (drg.value != "undefined") {
		paramTabPage[tabId] = drg;
	}
	var scoreQuota = [{
						"quotaCode" : "TotalScore",
						"quotaName" : "综合得分"
			},{
				"quotaCode" : "CapacityScore",
				"quotaName" : "产能得分"
			}, {
				"quotaCode" : "EfficiencyScore",
				"quotaName" : "效率得分"
			}, {
				"quotaCode" : "QualityScore",
				"quotaName" : "安全得分"
			}];
	paramTabPage[tabId].drg=perfQuotaDrg;
	paramTabPage[tabId].reg=perfQuotaReg;
		//加载科室绩效综合评价的div
	getWardScore(scoreQuota, "ward", "wardScore");
	//获取全部参与科室绩效指标比较汇总的科室
	drawWardPerfRards(perfQuotaDrg, perfQuotaReg);
	//全院各科室组DRGs指标综合比较汇总表
	loadTotalQuotaTable(totalQuota, "ward");
	//获取全部病区
	function drawWardPerfRards(perfQuotaDrg, perfQuotaReg) {
        //绘制指标复选框
        loadQuotaCheckbox();

		var map = drgUI.setAjaxData(tabId);
		//获取病区数据
		$.post(contextPath + '/DrgsIndexCal/getWardByCode.dhc', map).done(
				function(result) {
					if (result.success) {
						var wardAll = result.data;
						if (jQuery.isEmptyObject(wardAll)) {
							$('#' + tabId + ' #wardCodes ul').html("无数据");
						} else {
							//绘制复选框
							var str = "";
							$('#' + tabId + ' #wardCodes ul').html("");
							$.each(wardAll, function(n, value) {
								if(n==0){
									str += "<label><input checked='checked' type='checkbox' name='wardcode' value='"
										+ value.CODE+ "' descval='"+ value.NAME+ "'/>"
										+ value.NAME + "&nbsp;&nbsp;</label>";
								}else{
									str += "<label><input  type='checkbox' name='wardcode' value='"
										+ value.CODE+ "' descval='"+ value.NAME+ "'/>"
										+ value.NAME + "&nbsp;&nbsp;</label>";
								}
							});
							str += "<label><input type='checkbox' id='hspstd' name='wardcode' value='hspstd' descval='全院均值'  />全院均值&nbsp;&nbsp;</label>";
							$('#' + tabId + ' #wardCodes ul').append(str);
							if (wardAll.length > 5) {
								var strShowMore = "<div id='showMore'><a href='#' style='text-decoration:none'><i class='icon-plus-sign'style='font-size: 25px;'></i></a></div>";
								// 添加已经选中的复选框
								$('#' + tabId + ' #wardCodes')
										.append(strShowMore);
								var $category = $('#' + tabId
										+ ' #wardCodes ul label:gt(6):not(:last)');
								$category.hide();
								var $toggleBtn = $('#' + tabId + ' #showMore a');
								$toggleBtn.toggle(function() {
											$category.show();
											$(this)
													.find('i')
													.removeClass('icon-plus-sign')
													.addClass('icon-minus-sign')
													.css('color', 'red');
										}, function() {
											$category.hide();
											$(this)
													.find('i')
													.removeClass('icon-minus-sign')
													.addClass('icon-plus-sign')
													.css('color', '#428BCA');
										});
							}
							//复选框绑定事件
							$('#' + tabId + ' input[name="wardcode"]:checkbox')
									.on('ifChanged', function() {
										if ($('#'
												+ tabId
												+ ' input[name="wardcode"]:checkbox:checked')
												.size() == 0) {
											$(this).attr('checked', 'checked');
										}
                                        drawRadarBySelectedQuota(monitorType);
									});
						}
					}
                    //初始化icheck
                    $('#' + tabId + ' input').iCheck({
                        checkboxClass: 'icheckbox_square-blue',
                        radioClass: 'iradio_square-blue',
                        increaseArea: '10%' // optional
                    });
                    $('#' + tabId + ' #quotaPanel input').on('ifChanged', function () {
                        drawRadarBySelectedQuota(monitorType);
                    });
                    drawRadarBySelectedQuota(monitorType);
				});
	}

});
/**
 * 病区得分分析
 * @param {} totalQuota
 * @param {} monitorType
 * @param {} functionName
 */
function getWardScore(scoreQuota, monitorType, functionName) {
	var columns = [{
		"data" : "ddesc",
		"title" : "病区"
	 }, {
		"data" : "QuotaValue",
		"title" : "综合得分"
	}, {
		"data" : "CapacityScore",
		"title" : "产能得分"
	}, {
		"data" : "EfficiencyScore",
		"title" : "安全得分"
	}, {
		"data" : "QualityScore",
		"title" : "效率得分"
	},{
		"data":"",
		"title":"操作",
		"render":function(obj, type, full){
		   var isA=0
			if(toNextLayerBoolPerf(monitorType)){
				isA=1;
			}else{
				isA=0;
			}
			return "<a class='jumplink' href=\"javascript:loadHospDoctor('" + full.ccode + "','" + full.ddesc + "','" + monitorType+ "','"+isA+"')\">医生比较</a>";
		}
	}];
	var datas = [];
	var ajaxCnt = scoreQuota.length;
	for (var i in scoreQuota) {
		var quotaCode = scoreQuota[i].quotaCode;
		getPerfScoreTable(quotaCode, monitorType,
				function(quotaCode, data) {
					var data_s = [];
					data_s = data_s.concat(data);
					if (datas.length <= 0) {
						datas = data_s;
					}
					mergeListcc(datas, data_s,'ccode','',quotaCode);
					ajaxCnt--;
				});
	}
	var timer = setInterval(function() {
			if (ajaxCnt == 0) {
				clearInterval(timer);
				for(var i in datas){
					datas[i].QuotaValue=datas[i].TotalScore;
				}
				var paramsDataTables={order:[[1,'desc']],ordering:true};
				$("#" + tabId + " #wardScore_table").drgsDataTable(columns, datas,paramsDataTables);
			}
		}, 200);
};




